package com.itheima.homework;

import java.util.Random;

public class Test03 {
    public static void main(String[] args) {
        //定义长度为7的数组
        int[] arr = new int[7];
        //为数组元素赋值
        for (int i = 0; i < arr.length-1; i++) {
            int num = new Random().nextInt(32)+1;
            //标记位
            boolean flag = false;
            //如果是第一个元素,一定不会重复,直接赋值
            if(i == 0){
                arr[i] = num;
            }
            //判断其他元素是否会出现重复的情况
            else {
                for (int j = 0; j < arr.length-1; j++) {
                    if (num == arr[j]) {
                        flag = true;
                        break;
                    }
                }
                    if (flag) {
                        i--;
                    } else {
                        arr[i] = num;
                    }

            }

        }
        arr[arr.length-1] = new Random().nextInt(16)+1;
        for (int i = 0; i < arr.length; i++) {
            System.out.println(arr[i]);
        }

    }
}
